package com.baizhi.appController;

import com.baizhi.entity.*;
import com.baizhi.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


@RestController
@RequestMapping("/app")
public class AppController {
    @Autowired
    private BannerService bannerService;
    @Autowired
    private CmfzAlbumService cmfzAlbumService;
    @Autowired
    private CmfzArticleService cmfzArticleService;
    @Autowired
    private CmfzAudioService cmfzAudioService;
    @Autowired
    private CmfzLessonService cmfzLessonService;
    @Autowired
    private CmfzUserService cmfzUserService;
    @Autowired
    private AdminService adminService;

//    轮播图展示功能
    @GetMapping("/getAllBanner")
    public List<Banner> getAllBanner(){
        return bannerService.getAllBanner();
    }

//    吉祥妙音最新功能
    @GetMapping("/getSixAlbum")
    public List<CmfzAlbum> getSixAlbum(){
        return cmfzAlbumService.selectFirstSixAlbum();
    }

//    甘露妙宝最新功能
    @GetMapping("/getFirstTwoArticle/{userId}")
    public List<CmfzArticle> getFirstTwoArticle(@PathVariable(value = "userId")int userId){
        return cmfzArticleService.selectFirstTwoArticle(userId);
    }

//    展示专辑功能
    @GetMapping("/getAllAlbum")
    public List<CmfzAlbum> getAllAlbum(){
        return cmfzAlbumService.getAllAlbum();
    }

//    详情简介功能
    @GetMapping("/getOneAlbum/{albumId}")
    public CmfzAlbum getOneAlbum(@PathVariable(value = "albumId")int albumId){
        return cmfzAlbumService.getOneAlbum(albumId);
    }

//    章节列表功能
    @GetMapping("/getAudios/{albumId}")
    public List<CmfzAudio> getAudios(@PathVariable(value = "albumId")int albumId){
        return cmfzAudioService.getAudios(albumId);
    }

//    上师言教功能
    @GetMapping("/getGuruArticle/{userId}")
    public List<CmfzArticle> getGuruArticle(@PathVariable(value = "userId")int userId){
        return cmfzArticleService.getGuruArticle(userId);
    }

//    显密法要功能
    @GetMapping("/getNoGuruArticle/{userId}")
    public List<CmfzArticle> getNoGuruArticle(@PathVariable(value = "userId")int userId){
        return cmfzArticleService.getNoGuruArticle(userId);
    }

//    文章详情功能
    @GetMapping("/getOneArticle/{articleId}")
    public CmfzArticle getOneArticle(@PathVariable(value = "articleId")int articleId){
        return cmfzArticleService.getOneArticle(articleId);
    }

//    展示功课功能
    @GetMapping("/getMyLesson/{userId}")
    public List<CmfzLesson> getMyLesson(@PathVariable(value = "userId")int userId){
        return cmfzLessonService.getMyLesson(userId);
    }

//    添加功课功能
    @PostMapping("/addLesson")
    public Map addLesson(String lessonName,int userId){
        Map map=new HashMap();
        try {
            cmfzLessonService.addLesson(lessonName,userId);
            map.put("isAdd",true);
        } catch (Exception e) {
            e.printStackTrace();
            map.put("isAdd",false);
        }
        return map;
    }

    //    删除功课功能
    @PutMapping("/deleteLesson/{lessonId}")
    public Map deleteLesson(@PathVariable(value = "lessonId") Integer lessonId){
        Map map=new HashMap();
        try {
            cmfzLessonService.deleteLesson(lessonId);
            map.put("isDelete",true);
        } catch (Exception e) {
            e.printStackTrace();
            map.put("isDelete",false);
        }
        return map;
    }

//    个人信息功能
    @GetMapping("/selectOneUser/{userId}")
    public CmfzUser selectOneUser(@PathVariable(value = "userId")Integer userId){
        return cmfzUserService.selectOneUser(userId);
    }

//    修改个人密码功能
    @PatchMapping("/updatePassword/{userId}/{userPassword}")
    public Map updatePassword(@PathVariable(value = "userId")Integer userId,@PathVariable(value = "userPassword")String userPassword){
        Map map=new HashMap();
        try {
            map.put("isUpdate",true);
            cmfzUserService.updatePassword(userId,userPassword);
        } catch (Exception e) {
            e.printStackTrace();
            map.put("isUpdate",false);
        }
        return map;
    }

/*    //登录
    @RequestMapping("/login")
    public String login(String username, String password, HttpSession session){

        adminService.login(username,password);
        return "main/main";
    }*/
}
